#ifndef _BUOLA_GUI_WIDGETS_CTBTREERENDERER_H_
#define _BUOLA_GUI_WIDGETS_CTBTREERENDERER_H_

#include <buola/widgets/ctbrenderer.h>

namespace buola { namespace gui {

class CTBTreeRenderer : public CTBRenderer
{
public:
    CTBTreeRenderer(CTreeBox*);
    virtual ~CTBTreeRenderer();
    
public:
////////////// Event handling //////////////
    virtual void OnSize(const CGeometryEvent &pE);
    virtual void OnExpose(const CExposeEvent &pE);

    virtual void OnBigChange();
    virtual void OnNodeSelected(CTreeBox::SNode*);
    virtual void OnNodeAdded(CTreeBox::SNode*);
    virtual void OnNodeChanged(CTreeBox::SNode*);
    virtual void OnNodeRemoved(CTreeBox::SNode*);
    virtual void OnCursorChanged(CTreeBox::SNode*);
    virtual void OnFieldsChanged();
    virtual void OnXScrollChanged(int);
    
    void OnRulerMoved(TID pID,double pSize);

protected:
/////////////// protected functions //////////////
    //general functions
    void CalcAll();

    //item functions
    void InitNode(CTreeBox::SNode*);
    void DeinitNode(CTreeBox::SNode*);
    void PreshapeNode(CTreeBox::SNode*);    //calc min size
    void ShapeNode(CTreeBox::SNode*);       //calc size and shape
    void DrawNode(img::CGC*,CTreeBox::SNode*);
    void RedrawNode(CTreeBox::SNode*,bool);
    int HitTestNode(CTreeBox::SNode*,const CPoint_d&);
    int HitTestNode(CTreeBox::SNode*,const CRect_d&);

    //list functions
    void PreshapeAll();
    void ShapeAll();
    void PosAll(int=0);
    void DrawAll(img::CGC*);
    void DrawAll(img::CGC*,const CRect_d&);
    
    virtual CRect_d GetNodeRect(CTreeBox::SNode *pNode);
    virtual CSize_d GetIconSize()       {   return mIconSize;   }
    virtual CSize_d GetMaxImageSize()   {   return mIconSize;   }

    virtual PEditBox Edit(CTreeBox::SNode*);

    void FillRuler();

    //params
    CSize_d mIconSize;
    double mTextEnd;
    double mTotalEnd;
    double mMinTextHeight;

    //preshaping
    double mMaxIconWidth;
    double mMaxHeight;
    double mIndent;

    //positioning
    int mNumRows;
    img::PFont mFont;
    img::PFont mBoldFont;

    PRulerBox mRuler;
    CTreeBox::SField *mFirstField;
/////////////////// static data ////////////////////
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
